package edu.guet.trafficforecastsystem.mapper;

import edu.guet.trafficforecastsystem.model.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.sql.Date;


/**
 * Created by Caesar on 2017/5/21.
 */

@Mapper
public interface UserMapper {
   /* @Select({
            "select *",
            "from user",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results(value ={
            @Result(id=true, property="id",column="id",javaType=Integer.class,jdbcType=JdbcType.INTEGER),
            @Result(property="name",column="name",javaType=String.class,jdbcType= JdbcType.VARCHAR),
            @Result(property="password",column="password",javaType=String.class,jdbcType=JdbcType.VARCHAR),
            @Result(property="remarks",column="remarks",javaType=String.class,jdbcType=JdbcType.VARCHAR),
            @Result(property="createTime",column="create_time",javaType=Date.class,jdbcType=JdbcType.DATE),
            @Result(property="lastchangeTime",column="lastchange_time",javaType=Date.class,jdbcType=JdbcType.DATE),
    })
    User selectByPrimaryKey(@Param("id") Integer id);

    @Select({
            "select *",
            "from user",
            "where name = #{name,jdbcType=VARCHAR}"
    })
    @Results(value ={
            @Result(id=true, property="id",column="id",javaType=Integer.class,jdbcType=JdbcType.INTEGER),
            @Result(property="name",column="name",javaType=String.class,jdbcType= JdbcType.VARCHAR),
            @Result(property="password",column="password",javaType=String.class,jdbcType=JdbcType.VARCHAR),
            @Result(property="remarks",column="remarks",javaType=String.class,jdbcType=JdbcType.VARCHAR),
            @Result(property="createTime",column="create_time",javaType=Date.class,jdbcType=JdbcType.DATE),
            @Result(property="lastchangeTime",column="lastchange_time",javaType=Date.class,jdbcType=JdbcType.DATE),
    })
    User selectByName(@Param("name") String name);

    @Insert("INSERT `user` (name, passwd,remarks) VALUES (#{name}, #{password},#{remarks})")
    int addUser(User user);*/

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated
     */
    @Delete({
            "delete from user",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated
     */
    @Insert({
            "insert into user (id, name, ",
            "password, remarks, ",
            "create_time, lastchange_time)",
            "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
            "#{password,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR}, ",
            "#{createTime,jdbcType=TIMESTAMP}, #{lastchangeTime,jdbcType=TIMESTAMP})"
    })
    int insert(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated
     */
    int insertSelective(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated
     */
    @Select({
            "select",
            "id, name, password, remarks, create_time, lastchange_time",
            "from user",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("edu.guet.trafficforecastsystem.mapper.UserMapper.BaseResultMap")
    User selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, name, password, remarks, create_time, lastchange_time",
            "from user",
            "where name = #{name,jdbcType=VARCHAR}"
    })
    @ResultMap("edu.guet.trafficforecastsystem.mapper.UserMapper.BaseResultMap")
    User selectByName(String name);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated
     */
    int updateByPrimaryKeySelective(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated
     */
    @Update({
            "update user",
            "set name = #{name,jdbcType=VARCHAR},",
            "password = #{password,jdbcType=VARCHAR},",
            "remarks = #{remarks,jdbcType=VARCHAR},",
            "create_time = #{createTime,jdbcType=TIMESTAMP},",
            "lastchange_time = #{lastchangeTime,jdbcType=TIMESTAMP}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(User record);

}
